// pages/mine/mine.js
import {
    Minelogin,
    findUserOrder,
    Myoderyy,
    HomeListApi,
    vipmessage,
    authorize
} from "../../api/home.js";
Page({
    /**
     * 页面的初始数据
     */
    data: {
        top: null,
        name: null,
        headImg: null,
        userInfo: false,
        zzq: 2,
        tel:null,
        kname:""
    },
    //跳转我的订单
    bindViewTap() {
        wx.showLoading({
            title: '加载中',
          });
        //跳转到我的订单里边得儿时候让他先去请求我的订单的数据
        findUserOrder({
            "status": 0,
            "type": "E"
        }).then(res => {
            wx.hideLoading();
            console.log();
        })
        wx.navigateTo({
            url: "/pages/myorders/myorders"
        })
    },
    //跳转我的预约
    mydd() {
        wx.showLoading({
            title: '加载中',
          });
          Myoderyy({
            "status": 0
          }).then(res=>{
              console.log(res);
            wx.hideLoading();

          })
        wx.navigateTo({
            url: '/pages/my_booking/mybooking',
        })

    },
    //登录
    getUserInfo(e) {
        console.log(e);
    },
    userInfoHandler(e) {
        console.log(e);
    },
    //用户自己的头像授权
    login() {
        let that = this
        wx.getUserProfile({
            lang: "zh_CN",
            desc: "获取你的昵称、头像、地区及性别",
            success: response => {
                wx.setStorageSync("userinfo", response.userInfo)
                this.setData({
                    userInfo: response.userInfo
                })
                console.log(response);
            },
            fail: error => {
                // console.log(error)
                this.setData({
                    userInfo: null
                })
            }
        })
    },
   
    handleItemChange(e) {
        wx.login({
            success (res) {
             console.log(res);
            }
          })
        console.log(e);
        // debugger
        authorize({
            'code': e.detail.code,
            'encryptedData': e.detail.encryptedData,
            'iv': e.detail.iv,
        }).then(res => {
            console.log(res);
        })
    },
    //拨打电话
    myddTwo() {
      var _this = this
        wx.showModal({
            title: '是否要拨打',
            content: this.data.tel,
            success(res) {
                if (res.confirm) {
                    //联系我们 打电话
                    wx.makePhoneCall({
                        phoneNumber:  _this.data.tel,
                        success: (result) => {},
                        fail: () => {},
                        complete: () => {}
                    })

                } else if (res.cancel) {
                    // console.log('用户点击取消')
                }
            }
        })
    },
    //开通vip
    vip(){
        wx.navigateTo({
          url: '/pages/membership/membership',
        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const menu = wx.getMenuButtonBoundingClientRect();
        let system;
        wx.getSystemInfo({
            success(res) {
                system = res
                // console.log(res);
            }
        });
        const top = system.statusBarHeight + menu.height + (menu.top - system.statusBarHeight) * 2;

        let userInfo = wx.getStorageSync('userinfo')
        this.setData({
            top: top,
            userInfo: userInfo
        })
        HomeListApi().then(res=>{
          // console.log(res);/
          this.setData({
            tel:res.data.contactNumber
          })
        })
        //调用会员卡
        this.vipmessage()
    },
    //
    //会员卡信息请求
    async vipmessage (){
        const res = await vipmessage();
        // console.log(res);
        this.setData({
            kname:res.data.cardName
        })
      },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        //
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})